#!/bin/bash

source /mnt/rootfs/scripts/common.vars

exec 2>/dev/console
exec 1>/dev/console

clear
/mnt/rootfs/scripts/splash.sh
sleep 3
clear

echo
echo
echo
echo "        #######################################################################"
echo "        ##                                                                   ##"
echo "        ##                   Welcome to atvMod.com $VERSION                       ##"
echo "        ##                                                                   ##"
echo "        #######################################################################"
echo
sleep 1

echo " "
echo "        Starting atvMod.com $VERSION Patching Process..."
echo

# Preflight
mkdir /mnt/OSBoot
fsck.hfsplus -f /dev/sda3 > /dev/null
echo "        Checking Sanity of /dev/sda3 [ OSBoot ]...                        [ok]"
mount -t hfsplus -o rw,force /dev/sda3 /mnt/OSBoot
echo "        Mounting OSBoot...                                                [ok]"
touch /mnt/OSBoot/.readwrite
echo "        Keeping OSBoot readwrite...                                       [ok]"
mkdir /mnt/Media
fsck.hfsplus -f /dev/sda4 > /dev/null
echo "        Checking Sanity of /dev/sda4 [ Media ]...                         [ok]"
mount -t hfsplus -o rw,force /dev/sda4 /mnt/Media
echo "        Mounting Media...                                                 [ok]"

# Install SSH-2.0-dropbear_0.51
if [ -f /mnt/rootfs/stuff/dropbear/install.sh ]; then
  /mnt/rootfs/stuff/dropbear/install.sh 
  echo "        Installing SSH-2.0-dropbear_0.51...                               [ok]"
else
  echo "        Installing SSH-2.0-dropbear_0.51...                             [FAIL]"
fi

# Install BootLogo
if [ -f /mnt/rootfs/BootLogo.png ]; then
  mv /mnt/OSBoot/System/Library/CoreServices/BootLogo.png /mnt/OSBoot/System/Library/CoreServices/BootLogo.png.bak
  cp /mnt/rootfs/BootLogo.png /mnt/OSBoot/System/Library/CoreServices/BootLogo.png
  echo "        Installing Boot Logo...                                           [ok]"
else
  echo "        Installing Boot Logo...                                         [FAIL]"
fi

# Portflight 
umount /mnt/OSBoot
echo "        Unmounting OSBoot...                                              [ok]"
umount /mnt/Media
echo "        Unmounting Media...                                               [ok]"
echo
echo "          >>  atvMod.com $VERSION Process is DONE..."

sleep 10
sync &>/dev/null
umount /mnt/OSBoot
clear
/mnt/rootfs/scripts/done.sh

sleep 100000
